/*******************************************************
  > Copyright (C) 2024 ==IOT== All rights reserved.
  > File Name: receive.c
  > Author: wyf
  > Website:www.lv1.org
  > Created Time: 2024年08月05日 星期一 11时51分38秒
 ***************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>

int main(int argc, const char* argv[])
{

	int fd = 0;
	char dest[100] = {0};
	int res = 0;
	char ch = 't';
	int i =0;
	fd = open("./pipe",O_RDONLY);
	if(fd == -1)
	{
		perror("open");
		exit(-1);
	}

	sleep(10);

	int fp = 0;
	fp = open("./2.txt",O_RDWR,0770);
	int code = 0;
	//写
	 while (1) { 
        res = read(fd, dest, sizeof(dest) - 1);
		code = 0;
        dest[res] = '\0'; 
        printf("读取到的数据是: %s\n", dest);
		code = write(fp,dest,strlen(dest));
        for (i = 0; i < res; i++) {
            if (dest[i] == ch) {
                dest[i] = '\0'; 
                printf("在循环中: dest is %s\n", dest);
                close(fd);
                return 0; 
            }
        }
    }


	close(fd);

	return 0;
}
